package com.core.sdk.utils;

import android.app.Activity;
import android.content.Context;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.view.Window;
import android.view.WindowManager;

public class ScreenUtil {

	/** 标题栏高度 */
	public static int getTitleBarHeight(Activity act) {
		Rect rect = new Rect();
		Window win = act.getWindow();
		win.getDecorView().getWindowVisibleDisplayFrame(rect);
		int statusBarHeight = rect.top;
		int contentViewTop = win.findViewById(Window.ID_ANDROID_CONTENT).getTop();
		int titleBarHeight = contentViewTop - statusBarHeight;
		return titleBarHeight;
	}

	/** 通知栏高度 */
	public static int getStatusBarHeight(Activity act) {
		Rect rect = new Rect();
		Window win = act.getWindow();
		win.getDecorView().getWindowVisibleDisplayFrame(rect);
		int statusBarHeight = rect.top;
		return statusBarHeight;
	}

	/** 获取屏幕的高宽度 */
	public static DisplayMetrics getDisplayMetrics(Context context) {
		DisplayMetrics outMetrics = new DisplayMetrics();
		WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		wm.getDefaultDisplay().getMetrics(outMetrics);
		return outMetrics;
	}

	/** dp转px */
	public static int dip2px(Context context, float dpValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dpValue * scale + 0.5f);
	}

	/** px转dp */
	public static int px2dip(Context context, float pxValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (pxValue / scale + 0.5f);
	}

	/*
	 * 
	 * getLocationOnScreen
	 * 计算该视图在全局坐标系中的x，y值，（注意这个值是要从屏幕顶端算起，也就是包括了通知栏的高度）//获取在当前屏幕内的绝对坐标
	 * getLocationInWindow 计算该视图在它所在的widnow的坐标x，y值，//获取在整个窗口内的绝对坐标
	 * 
	 * getLeft , getTop, getBottom, getRight, 这一组是获取相对在它父亲里的坐标 
	 * int[] location = new int[2] ;
	 * view.getLocationInWindow(location); //获取在当前窗口内的绝对坐标
	 * view.getLocationOnScreen(location);//获取在整个屏幕内的绝对坐标 location
	 * [0]--->x坐标,location [1]--->y坐标
	 */

}
